var app =new Vue({
	el:"#container",
	data:{
		pageNum:1,
		pageSize:5,
		username:"",
		jobNumber:"",
		pageInfo:[],
	},
	mounted:function (){
		this.getPage(this.pageNum,this.pageSize);
	},
	methods:{
		getPage:function (pageNum,pageSize,username,jobNumber){
			var data=new URLSearchParams();
			data.append("pageNum",pageNum);
			data.append("pageSize",pageSize);
			data.append("username",username);
			data.append("jobNumber",jobNumber);
			axios({
				method: "post",
				url:"yly-api/admin/getPage",
				data:data,
				headers:{"token":localStorage.token,"url":window.location.pathname}
			}).then(function (res){
				console.log(res.data);
				if (res.data.code==200){
					app.pageInfo=res.data.data;
					app.pageNum=res.data.data.pageNum;
					app.pageSize=res.data.data.pageSize;
				}else if (res.data.code==500){
					location.href="500.html";
				}
			}).catch(function (error){
				console.log(error.response.status);
				if (error.response.status==401){
					alert("请先登录!");
					location.href="login.html";
				}else if (error.response.status==403){
					alert("用户已过期，请重新登录！");
					localStorage.token=null;
					location.href="login.html";
				}
			})
		},
		firstPage:function () {
			this.getPage(this.pageInfo.navigateFirstPage,this.pageSize,this.username,this.jobNumber);
		},
		lastPage:function (){
			this.getPage(this.pageInfo.navigateLastPage,this.pageSize,this.username,this.jobNumber);
		},
		number:function (page) {
			this.getPage(page,this.pageSize,this.username,this.jobNumber);
		},
		query:function (){
			this.getPage(this.pageInfo.navigateFirstPage,this.pageSize,this.username,this.jobNumber);
		},
		del:function (id){
			let data=new URLSearchParams();
			data.append("id",id);
			if(confirm("是否要删除该员工？")){
				axios({
					method: "post",
					url: "yly-api/admin/delEmpAccount",
					data: data,
					headers: {"token":localStorage.token,"url":window.location.pathname}
				}).then(function (res) {
					console.log(res.data);
					if (res.data.code==200){
						if (res.data.data==true){
							app.getPage(app.pageNum,app.pageSize,app.username,app.jobNumber);
							alert("删除成功");
						}else {
							alert("删除失败，请联系管理员！");
						}
					}else if (res.data.code==500){
						location.href="500.html";
					}
				}).catch(function (error){
					console.log(error.response.status);
					if (error.response.status==401){
						alert("请先登录!");
						location.href="login.html";
					}else if (error.response.status==403){
						alert("用户已过期，请重新登录！");
						localStorage.token=null;
						location.href="login.html";
					}
				})
			}
		},
		modify:function (id){
			location.href="/director-modify.html?id="+id;
		}
	}
});
